package com.common;

import com.swtplayer.MainActivity;
import com.swtplayer.MapActivity;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.Log;

public class GuidePageChangeListener implements OnPageChangeListener {

	int _totalpage = 0;
	Context _context;	
	ViewPageHandler _handler;

	public GuidePageChangeListener(int totalpage, Context context,ViewPageHandler handler) {
		_totalpage = totalpage;
		_context = context;
		_handler=handler;
	}

	public void onPageScrollStateChanged(int arg0) {
		// TODO Auto-generated method stub

	}

	public void onPageScrolled(int arg0, float arg1, int arg2) {
		// TODO Auto-generated method stub

	}
 
	public void onPageSelected(int position) {

		// TODO Auto-generated method stub

        Log.w("scroll", position+""+_totalpage);
        
		if (position == _totalpage-1) {
			
			if (_context.getClass().getSimpleName().equals("WelcomeActivity"))
			{
				   Thread thread=new Thread(new Runnable() {					
					@Override
					public void run() {
						Intent intent = new Intent();
				        intent.setClass(_context, MapActivity.class);
				        _context.startActivity(intent);			
					}
				});
				   
				try {
					thread.sleep(1000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				thread.start();
				    
				
			}
			else {
				_handler.what.set(-1);
				_handler.sendEmptyMessageDelayed(position, _handler.delayedTime);
			}
			
		}
		else {
		    	_handler.sendEmptyMessageDelayed(position, _handler.delayedTime);
		}

	}

}
